package com.m3839.sdk.pay.bean;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 描述信息:支付信息,用户支付时传参
 *
 * @author xuzhiwei
 * @create 2020/8/3
 */
public class PayInfo implements Parcelable {

  /**
   * 商品名称
   */
  public String goodsName;
  /**
   * 价格
   */
  public int money;

  /**
   * 分服标识
   */
  public int server;

  /**
   * 游戏自定义订单号，即充值中心的mark
   */
  public String cpOrderId;

  /**
   * 透传字段
   */
  public String ext;

  @Override
  public int describeContents() { return 0; }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.goodsName);
    dest.writeInt(this.money);
    dest.writeInt(this.server);
    dest.writeString(this.cpOrderId);
    dest.writeString(this.ext);
  }

  public PayInfo() {}

  protected PayInfo(Parcel in) {
    this.goodsName = in.readString();
    this.money = in.readInt();
    this.server = in.readInt();
    this.cpOrderId = in.readString();
    this.ext = in.readString();
  }

  public static final Creator<PayInfo> CREATOR = new Creator<PayInfo>() {
    @Override
    public PayInfo createFromParcel(Parcel source) {
      return new PayInfo(source);
    }

    @Override
    public PayInfo[] newArray(int size) {return new PayInfo[size];}
  };

  @Override
  public String toString() {
    return "HykbPayInfo{" +
        "goodsName='" + goodsName + '\'' +
        ", money=" + money +
        ", server=" + server +
        ", cpOrderId='" + cpOrderId + '\'' +
        ", ext='" + ext + '\'' +
        '}';
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof PayInfo)) {
      return false;
    }
    PayInfo payInfo = (PayInfo) o;
    return money == payInfo.money
            && server == payInfo.server
            && goodsName.equals(payInfo.goodsName)
            && cpOrderId.equals(payInfo.cpOrderId)
            && ext.equals(payInfo.ext);
  }

  @Override
  public int hashCode() {
    Object[] a = {goodsName, money, server, cpOrderId, ext};

    int result = 1;
    for (Object element : a) {
      result = 31 * result + (element == null ? 0 : element.hashCode());
    }

    return result;
  }
}
